﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Password</title>
</head>
<body>

    <form method="post" asp-controller="Account" asp-action="ResetPassword" asp-antiforgery="true">
        @Html.AntiForgeryToken()
        <div class="text-danger">
        </div>

        <input type="hidden" id="UserId" name="UserId" value="@Model.UserId" />
        <input type="hidden" id="Token" name="Token" value="@Model.Token" />

        <div class="form-group">
            <label for="NewPassword">Новый пароль</label>
            <input type="password" id="NewPassword" name="NewPassword" class="form-control" />
            <span class="text-danger">
            </span>
        </div>

        <div class="form-group">
            <label for="ConfirmPassword">Подтвердите новый пароль</label>
            <input type="password" id="ConfirmPassword" name="ConfirmPassword" class="form-control" />
            <span class="text-danger">
            </span>
        </div>
        <p></p>
        <button type="submit" class="btn btn-primary">Сбросить пароль</button>
    </form>
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

    <script>
        $(document).ready(function () {
            $('form').submit(function (e) {
                e.preventDefault();

                var formData = {
                    UserId: $('#UserId').val(),
                    Token: $('#Token').val(),
                    NewPassword: $('#NewPassword').val(),
                    ConfirmPassword: $('#ConfirmPassword').val()
                };

                $.ajax({
                    type: 'POST',
                    url: 'reset-password',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify(formData),
                    headers: {
                        'RequestVerificationToken': $('input[name="__RequestVerificationToken"]').val()
                    },
                    success: function (response) {
                        console.log(response);
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
            });
        });
    </script>
</body>
</html>
